package com.hongxun.modules.bss.service.impl;

import java.math.BigDecimal;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.APCostDao;
import com.hongxun.modules.bss.entity.APCostEntity;
import com.hongxun.modules.bss.service.APCostService;



@Service("aPCostService")
public class APCostServiceImpl implements APCostService {
	@Autowired
	private APCostDao aPCostDao;
	
	@Override
	public APCostEntity queryObject(String guid){
		return aPCostDao.queryObject(guid);
	}
	
	@Override
	public List<APCostEntity> queryList(Map<String, Object> map){
		return aPCostDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return aPCostDao.queryTotal(map);
	}
	
	@Override
	public void save(APCostEntity aPCost){
		if(aPCost.getGuid()==null||aPCost.getGuid().equals("")) {

			aPCost.setGuid(UUID.randomUUID().toString());
		}
		aPCostDao.save(aPCost);
	}
	
	@Override
	public void update(APCostEntity aPCost){
		aPCostDao.update(aPCost);
	}
	
	@Override
	public void delete(String guid){
		aPCostDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		aPCostDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<APCostEntity> entities) {
		for (APCostEntity d : entities) {
			if (d.getPCDatastate().equals("删除")) {
				aPCostDao.delete(d.getGuid());
			} else {
				if(d.getPCPrice()==null)
				{
					d.setPCPrice(BigDecimal.ZERO);
				}
				APCostEntity apCostEntity = aPCostDao.queryObject(d.getGuid());
				if (apCostEntity == null) {
					aPCostDao.save(d);
				} else {
					aPCostDao.update(d);
				}
			}
		}
	}
}
